﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using UniRlv.Utility;
using UniRlv.Utility.Extend;

namespace UniRlv.UI.Main.WarerHourseIn
{
    public partial class FrmRelatitonshipCheck : UniRlv.UI.Main.FrmBase
    {
        public FrmRelatitonshipCheck()
        {
            InitializeComponent();
        }

        private void FrmRelatitonshipCheck_Load(object sender, EventArgs e)
        {
            toolBtnQuery.Visible = true;
            toolBtnQuery.Click += toolBtnQuery_Click;

            WorkSpace.GetInstance().CodeEditEvent += CodeEditEventHandler;
        }

        private void CodeEditEventHandler(object sender, CodeEditEventArg e)
        {
            CallCtrlWithThreadSafety.SetText(txtTip, e.Tip, this);
        }

        private void toolBtnQuery_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtParent.Text) && !string.IsNullOrEmpty(txtSon.Text))
            {
                QueryCode(txtParent.Text, txtSon.Text);
            }
            else
            {
                MessageBox.Show("父码或者子码不能为空！");
                return;
            }
        }

        public override void OnScanCode(string orgCode, string validCode)
        {
            if (string.IsNullOrEmpty(txtParent.Text))
            {
                txtParent.Text = validCode;
                txtSon.Focus();
                txtSon.SelectAll();
            }
            else
            {
                txtSon.Text = validCode;
            }
        }

        private void txtParent_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                if (!string.IsNullOrEmpty(txtParent.Text))
                {
                    txtSon.Focus();
                    txtSon.SelectAll();
                }
                
            }
        }

        private void txtSon_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                if (!string.IsNullOrEmpty(txtSon.Text))
                {
                    QueryCode(txtParent.Text, txtSon.Text);
                }
            }
        }

        void QueryCode(string p, string s)
        {
            //string msg = string.Empty;
            //bool b = CodePrcUtility.CheckRlt(new List<string>() { p,s}, ref msg);
            WorkSpace.GetInstance().PutEditData(new List<string>() { p, s }, COL.exception_proccess.EP_QUERY_RLT);
            //txtTip.Text = msg;

            txtParent.Text = "";
            txtSon.Text = "";
        }
    }
}
